package com.zhao.web.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhao.data.mapper.RoleMapper;
import com.zhao.data.model.Role;
import com.zhao.data.repository.RoleRepository;

/** 基于角色的访问控制
 * 
 * 暂时不再自定义权限控制，权且使用Spring Security进行控制
 * 
 * @author zhaoyongfei
 *
 */
@Deprecated
@Controller
public class RoleController extends BackBaseController {
	
	@Autowired
	RoleMapper roleMapper;
	
	@Autowired
	RoleRepository roleRepository;
	
	public static final String PATH = "role";
	public static final String INSERT_PATH=PATH+"/insert";
	public static final String UPDATE_PATH=PATH+"/update";
	public static final String DELETE_PATH=PATH+"/delete";


	
	@ModelAttribute("pager")
    public PageInfo<Role> pager() {
		PageHelper.startPage(pageNum, pageSize);
		List<Role> list = roleMapper.selectAll();
		PageInfo<Role> pager = new PageInfo<Role>(list);
        return pager;
    }
	
    
	@RequestMapping(value=INSERT_PATH,method={RequestMethod.POST})
    public String insert(@ModelAttribute("role")Role role, final BindingResult bindingResult) {
		roleMapper.insert(role);
		return viewName;
    }
	
	@RequestMapping(value=UPDATE_PATH,method={RequestMethod.POST})
    public String update(@ModelAttribute("role")Role role, final BindingResult bindingResult) {
		roleMapper.updateByPrimaryKey(role);
		return viewName;
    }
	
	@RequestMapping(value=DELETE_PATH,method={RequestMethod.POST})
    public String delete(@ModelAttribute("role")Role role, final BindingResult bindingResult) {
		roleMapper.deleteByPrimaryKey(role.getId());
		return viewName;
    }
    
	@RequestMapping(PATH)
	public String view(Map<String, Object> model,HttpServletRequest request) {
		
		return viewName;
	}
	
	@Override
	public void init() {
		title="角色管理";
		viewName="back/role";
	}

}
